<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        table td{
            text-align: center;
        }
    </style>
    <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
</head>
<body>
<a href="toAdd">新生注册</a>
<%--<a href="${pageContext.request.contextPath}/student/toAdd">新生注册</a>--%>
<p>
${msg}
</p>
<p>
    <form action="${pageContext.request.contextPath}/student/search" id="seachForm">
     <input type="hidden" name="pageNo" id="pageNo" value="${p.pageNo}"/>
     <input type="search" name="sname" placeholder="学生姓名" value="${sname}"/>
     <input type="search" name="wechat" placeholder="wechat" value="${wechat}"/>
     <input type="search" name="qq" placeholder="QQ" value="${qq}"/>
     入学时间从:<input type="date" name="dateStart" value="<fmt:formatDate value='${dateStart}' pattern='yyyy-MM-dd'/>"/>-<input type="date" name="dateEnd" value="<fmt:formatDate value='${dateEnd}' pattern='yyyy-MM-dd'/>"/>
    <input type="submit" value="搜索"/>
    </form>
</p>
<table border="1" cellpadding="0" cellspacing="0" align="center" style="width: 90%">
    <caption>学生信息</caption>
    <tr>
        <td>学号</td>
        <td>姓名</td>
        <td>性别</td>
        <td>入学时间</td>
        <td>QQ</td>
        <td>手机号</td>
        <td>微信</td>
        <td>操作</td>
    </tr>

    <c:forEach items="${p.datas}" var="s">
    <tr>
        <td>${s.stuno}</td>
        <td>${s.sname}</td>
        <td>${s.sex}</td>
        <td>${s.enterdate}</td>
        <td>${s.qq}</td>
        <td>${s.telephone}</td>
        <td>${s.wechat}</td>
        <td>
            <a href="">查看</a>
            <a href="#">修改</a>
            <a href="del-${s.stuno}">删除</a>
            <a href="showScore.do?stuno=${s.stuno}">查看成绩</a>
            <a href="#?stuno=${s.stuno}">添加成绩</a>
        </td>
    </tr>
    </c:forEach>
</table>
<p align="center" class="pager">
    <a id="prev" href="#" data-page="1">首页</a>
    <c:if test="${p.pageNo>1}">
    <a id="prev" href="#" data-page="${p.pageNo-1}">上一页</a>
    </c:if>
    <input type="number" name="pa" value="${p.pageNo}" style="width: 40px" size="4" min="1" max="${p.totalPages}"/>/${p.totalPages}
    <button type="button" id="gotoPage">Go</button>

    <c:if test="${p.pageNo<p.totalPages}">
    <a href="#" id="next" data-page="${p.pageNo+1}">下一页</a>
    </c:if>
    <a href="#" id="next" data-page="${p.totalPages}">最后一页</a>
</p>
<script>
    $(function () {
        $("form#seachForm :submit").click(function () {
            $("#pageNo").val(1);//每次搜索，页号从1开始
            return true;
        });
        $(".pager #gotoPage").click(function () {
            let pageNo=$(this).prev().val();
            if(pageNo<1 || pageNo>${p.totalPages}){
                alert("值太大");
                return false;
            }
            $("form#seachForm #pageNo").val(pageNo);
            $("form#seachForm").submit();//手工提交表单
            return false;
        });
        $(".pager a").click(function () {
            let pageNo= $(this).data("page");
            //alert(pageNo);
            //$(this).attr("data-page");
            $("#pageNo").val(pageNo);
            $("form#seachForm").submit();//手工提交表单
            return false;//让a 链接失效
        });
    });
</script>
</body>
</html>
